{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "325f602f",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "c368e718",
   "metadata": {},
   "outputs": [],
   "source": [
    "df='第二版数据.csv'\n",
    "data=pd.read_csv(df,encoding='ANSI')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "727c0125",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>timestamp</th>\n",
       "      <th>link_id</th>\n",
       "      <th>throughput</th>\n",
       "      <th>delay</th>\n",
       "      <th>jitter</th>\n",
       "      <th>loss</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>56:56.6</td>\n",
       "      <td>2-3-2-3</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.516461</td>\n",
       "      <td>1.516461</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>56:56.6</td>\n",
       "      <td>3-3-2-4</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.475573</td>\n",
       "      <td>1.475573</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>56:56.6</td>\n",
       "      <td>1-2-2-2</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.227856</td>\n",
       "      <td>1.227856</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>56:56.6</td>\n",
       "      <td>4-3-2-5</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.355648</td>\n",
       "      <td>1.355648</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  timestamp  link_id  throughput     delay    jitter  loss\n",
       "0   56:56.6  2-3-2-3         0.0  1.516461  1.516461   0.0\n",
       "1   56:56.6  3-3-2-4         0.0  1.475573  1.475573   0.0\n",
       "2   56:56.6  1-2-2-2         0.0  1.227856  1.227856   0.0\n",
       "3   56:56.6  4-3-2-5         0.0  1.355648  1.355648   0.0"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.head(4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "1ec248b8",
   "metadata": {},
   "outputs": [],
   "source": [
    "flag=data['link_id'].str.split(\"-\",expand=True)\n",
    "data[\"入端口\"]=flag[0]\n",
    "data[\"出端口\"]=flag[3]\n",
    "data[\"组合\"]=flag[0]+flag[3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "fc15475f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>timestamp</th>\n",
       "      <th>link_id</th>\n",
       "      <th>throughput</th>\n",
       "      <th>delay</th>\n",
       "      <th>jitter</th>\n",
       "      <th>loss</th>\n",
       "      <th>入端口</th>\n",
       "      <th>出端口</th>\n",
       "      <th>组合</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>56:56.6</td>\n",
       "      <td>2-3-2-3</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.516461</td>\n",
       "      <td>1.516461</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2</td>\n",
       "      <td>3</td>\n",
       "      <td>23</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>56:56.6</td>\n",
       "      <td>3-3-2-4</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.475573</td>\n",
       "      <td>1.475573</td>\n",
       "      <td>0.0</td>\n",
       "      <td>3</td>\n",
       "      <td>4</td>\n",
       "      <td>34</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>56:56.6</td>\n",
       "      <td>1-2-2-2</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.227856</td>\n",
       "      <td>1.227856</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>56:56.6</td>\n",
       "      <td>4-3-2-5</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.355648</td>\n",
       "      <td>1.355648</td>\n",
       "      <td>0.0</td>\n",
       "      <td>4</td>\n",
       "      <td>5</td>\n",
       "      <td>45</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  timestamp  link_id  throughput     delay    jitter  loss 入端口 出端口  组合\n",
       "0   56:56.6  2-3-2-3         0.0  1.516461  1.516461   0.0   2   3  23\n",
       "1   56:56.6  3-3-2-4         0.0  1.475573  1.475573   0.0   3   4  34\n",
       "2   56:56.6  1-2-2-2         0.0  1.227856  1.227856   0.0   1   2  12\n",
       "3   56:56.6  4-3-2-5         0.0  1.355648  1.355648   0.0   4   5  45"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.head(4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "38fc43a0",
   "metadata": {},
   "outputs": [],
   "source": [
    "data.to_csv(\"第二版处理后的test.csv\",index=False,encoding='ANSI')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "8ea8e7e7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>timestamp</th>\n",
       "      <th>link_id</th>\n",
       "      <th>throughput</th>\n",
       "      <th>delay</th>\n",
       "      <th>jitter</th>\n",
       "      <th>loss</th>\n",
       "      <th>入端口</th>\n",
       "      <th>出端口</th>\n",
       "      <th>组合</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>00:56:56.600000</td>\n",
       "      <td>4-3-2-5</td>\n",
       "      <td>0</td>\n",
       "      <td>1.355648</td>\n",
       "      <td>1.355648</td>\n",
       "      <td>0.0</td>\n",
       "      <td>4</td>\n",
       "      <td>5</td>\n",
       "      <td>45</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>00:57:09.600000</td>\n",
       "      <td>4-3-2-5</td>\n",
       "      <td>3200</td>\n",
       "      <td>1.294017</td>\n",
       "      <td>0.061631</td>\n",
       "      <td>0.0</td>\n",
       "      <td>4</td>\n",
       "      <td>5</td>\n",
       "      <td>45</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>00:57:36.700000</td>\n",
       "      <td>4-3-2-5</td>\n",
       "      <td>0</td>\n",
       "      <td>1.390100</td>\n",
       "      <td>1.390100</td>\n",
       "      <td>0.0</td>\n",
       "      <td>4</td>\n",
       "      <td>5</td>\n",
       "      <td>45</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>00:57:49.700000</td>\n",
       "      <td>4-3-2-5</td>\n",
       "      <td>4930</td>\n",
       "      <td>1.552820</td>\n",
       "      <td>0.162721</td>\n",
       "      <td>0.0</td>\n",
       "      <td>4</td>\n",
       "      <td>5</td>\n",
       "      <td>45</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "         timestamp  link_id  throughput     delay    jitter  loss  入端口  出端口  \\\n",
       "0  00:56:56.600000  4-3-2-5           0  1.355648  1.355648   0.0    4    5   \n",
       "1  00:57:09.600000  4-3-2-5        3200  1.294017  0.061631   0.0    4    5   \n",
       "2  00:57:36.700000  4-3-2-5           0  1.390100  1.390100   0.0    4    5   \n",
       "3  00:57:49.700000  4-3-2-5        4930  1.552820  0.162721   0.0    4    5   \n",
       "\n",
       "   组合  \n",
       "0  45  \n",
       "1  45  \n",
       "2  45  \n",
       "3  45  "
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df2='45.xlsx'\n",
    "data2=pd.read_excel(df2)\n",
    "data2.head(4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "0f636203",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0          0\n",
       "1       3200\n",
       "2          0\n",
       "3       4930\n",
       "4        753\n",
       "        ... \n",
       "1229     672\n",
       "1230     720\n",
       "1231     672\n",
       "1232     672\n",
       "1233     720\n",
       "Name: throughput, Length: 1234, dtype: int64"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data2[\"throughput\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "7d233adf",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "pandas.core.series.Series"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(data2[\"throughput\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "faa79156",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[   0 3200    0 ...  672  672  720]\n"
     ]
    }
   ],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "# 创建一个Series对象\n",
    "s = data2[\"throughput\"]\n",
    "# 将Series转换为ndarray\n",
    "arr = s.to_numpy()\n",
    "# 输出数组\n",
    "print(arr)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "653168db",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
